{% extends 'base.html' %}
{% block head %}
	<link href="{{ path }}js/plugins/datatables/DT_bootstrap.css" rel="stylesheet">
	<link href="{{ path }}js/plugins/responsive-tables/responsive-tables.css" rel="stylesheet"> 
    
    <script src="{{ path }}js/demos/demo.tables.js"></script>
    <script src="{{ path }}js/plugins/datatables/jquery.dataTables.js"></script>
    <script src="{{ path }}js/plugins/datatables/DT_bootstrap.js"></script>
	<script src="{{ path }}js/plugins/responsive-tables/responsive-tables.js"></script>

{% endblock %}
{% load humanize %}
{% block jquery %}	
    
	$("#facultad").change(function () {
		$('#semestre').find('option').remove().end();
		$("#facultad option:selected").each(function () {
			semestres = $(this).attr("semestres") + " ";
		});
         
        for(i=0; i<=semestres; i++){
            $('#semestre').append($('<option></option>').attr('value', (i) ).text((i)));
        }
		
	});
{% endblock %}

{% block javascript %}
    function eliminar(factura_id){
            $.ajax({
              url: "/inventario/facturas_venta/borrar/",
              type: "POST",
              data : {factura_id:factura_id, 
                       },
              dataType: "html",
              success: function(datos) {
                    if(datos==1){
                        location.reload(true);
                    }
                    else{
                        alert("Se ha producido un error borrando la factura." + datos);
                    }
                  
              }
          });
        return false;
    }
{% endblock %}

{% block contenido %}
	{{ request.session.control }}
    	
		<div class="span12">
            <div class="widget">	
                <div class="widget widget-table">   
                    <div class="widget-header">						
                        <h3>
                            <i class="icon-th-list"></i>
                            Facturas de venta
                        </h3>
                    </div> <!-- /widget-header -->
                    <form id="frm_borrar" action="/inventario/facturas_venta/borrar/" method="post">
                    <div class="widget-content">
                        {% csrf_token %}
                        <table class="table table-striped table-bordered table-highlight" id="example">
                            <thead>
                            <tr>
                                <th width="6%" align="center">No.</th>
                                <th width="15%" align="center">Cliente</th>
                                <th width="10%" align="center">Fecha emisión</th>
                                <th width="8%" align="center">Sede</th>
                                <th width="8%" align="center">Subtotal</th>
                                <th width="8%" align="center">Iva</th>
								<th width="8%" align="center">Retefuente</th>
                                <th width="8%" align="center">ReteIva</th>
								<th width="8%" align="center">Transporte</th>
								<th width="8%" align="center">Ajuste</th>
                                <th width="8%" align="center">Total</th>
                                <th width="15%" align="center">Observaciones</th>
                                <th width="5%" align="center">Pagada</th>
                                <th width="4%" align="center">Editar</th>
                                <th width="4%" align="center">Borrar</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for factura in Facturas %}
                                <tr class="{% cycle '' 'odd' %}">
                                    <td align="right"><label>{{ factura.numero }}</label></td>
                                    <td align="left"><label>{{ factura.cliente }}</label></td>
                                    <td align="center"><label>{{ factura.fecha_emision|date:'d-m-Y' }}</label></td>
                                    <td align="left"><label>{{ factura.sede }}</label></td>
                                    <td align="right"><label>{{ factura.subtotal|intcomma }}</label></td>
                                    <td align="right"><label>{{ factura.iva|intcomma }}</label></td>
									<td align="right"><label>{{ factura.retefuente|default_if_none:0 }}</label></td>
                                    <td align="right"><label>{{ factura.reteiva|default_if_none:0 }}</label></td>
									<td align="right"><label>{{ factura.transporte|default_if_none:0 }}</label></td>
                                    <td align="right"><label>{{ factura.ajuste_peso|default_if_none:0 }}</label></td>
									<td align="right"><label>{{ factura.total|intcomma }}</label></td>
                                    <td align="left"><label>{{ factura.observacion }}</label></td>
                                    <td align="center"><label>{% if factura.pagada %}<img src="{{ path }}img/validate/valid.png"/>{% else %}<img src="{{ path }}img/validate/error.png" />{% endif %}</label></td>
                                    <td><a href="/inventario/facturas_venta/buscar/{{factura.id}}/" id="fac_{{ factura.id }}" data-toggle="modal" class="acc_factura"><img src="{{ path }}images/24x24/edit.png" /></a></td>
                                    <td><a href="#"><img src="{{ path }}images/delete.png" width="16" height="16" alt="Eliminar" onclick="if(confirm('Al eliminar una factura serán borrados los productos relacionados del inventario. ¿Desea eliminar esta factura?')){eliminar({{ factura.id }});}"/></a></td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div> <!-- /. widget-content -->
                    <div class="modal-footer">
                        <a href="/inventario/facturas_venta/nuevo" data-toggle="modal" class="btn btn-primary btn-medium">Nuevo</a>
                    </div>
                    </form>
                </div> <!-- /. widget-table -->
            </div> <!-- /. widget -->
        </div> <!-- /. span12 -->
{% endblock %}